Notes on Bitblt

关于位块传输的注释
===============

    General purpose ROP compiler

    通用ROP编译器
    ----------------------------

    Given a ternary ROP is there anyway to know if it needs a pattern?

    Does it needs a source?  How many times does it use the destination?

    Think of a polynomial that can express all possible ROP operations:

    给定一个三值ROP，是否有必要知道它是否需要模式？

    它需要来源吗？它使用目的地多少次？

    考虑一个多项式，它可以表示所有可能的ROP操作：

      1)  a  + a D + a S + a P + a  SD + a  DP + a  SP + a   DSP
           0    d     s     p     sd      dp      sp      dsp


    Also note that a is from the set of binary digits {0, 1}

    A ROP is currently expressed by taking a bit pattern for the Pattern,

    Source and Destination and applying the bitwise operations (and, or,

    xor, not) to the values.  All math is done modulo 256.

    还要注意，a来自二进制数字集{0,1}

    ROP当前通过为模式取位模式来表示，

    源和目标，并应用逐位运算（和、或、，

    异或，非）到值。所有数学都是256模。


      2)  P = 240 (11110000), S = 204 (11001100), D = 170 (10101010)


    An example ROP for taking the bitwise or of the Source and Pattern,

    anding it with the destination and taking the bitwise not would be:

    用于按位取源和模式的或的ROP示例，

    与目的地匹配并按位不匹配将是：

        ~((P | S) & D)
        ~((240 | 204) & 170)        ~((11110000 | 11001100) & 10101010)
        ~(252 & 170)                ~(11111100 & 10101010)
        ~168                        ~10101000
        87                           01010111

    The ROP would therefore be 87.  Now we have to map the bits in the

    ROP to the terms of the polynomial.  Think of the bits in the ROP

    as a vector.  The a terms in the polynomial as another vector.  A

    matrix can be found to map one vector to the other.

    因此，ROP将为87。现在我们必须在

    ROP到多项式的项。想想ROP中的钻头

    作为向量。多项式中的a项作为另一个向量。A类

    可以找到矩阵来将一个向量映射到另一个向量。


      3) [    ]     [                 ]     [      ]
           b          1 0 0 0 0 0 0 0         a
            0                                  0
           b          1 1 0 0 0 0 0 0         a
            1                                  d
           b          1 0 1 0 0 0 0 0         a
            2                                  s
           b          1 1 1 0 1 0 0 0         a
            3    X                       =     p
           b          1 0 0 1 0 0 0 0         a
            4                                  ds
           b          1 1 0 1 0 1 0 0         a
            5                                  dp
           b          1 0 1 1 0 0 1 0         a
            6                                  sp
           b          1 1 1 1 1 1 1 1         a
         [  7 ]     [                 ]     [  dsp ]


    From this formulas for the dependency of bits in the ROP can be found

    for the terms of the polynomial.

    从这个公式中可以找到ROP中位的相关性

    对于多项式的项。

      4)  a  = b
           0    0

          a  = b  + b
           d    0    1

          a  = b  + b
           s    0    2

          a  = b  + b
           p    0    4

          a  = b  + b  + b  + b
           ds   0    1    2    3

          a  = b  + b  + b  + b
           dp   0    1    4    5

          a  = b  + b  + b  + b
           sp   0    2    4    6

          a  = b  + b  + b  + b  + b  + b  + b  + b
           dsp  0    1    2    3    4    5    6    7


    Dependency on a term can be tested with a parity test, if an odd

    number of the bits are true, the term needs to be evaluated.  For

    example, any odd ROP will have to have the a  term evaluated.  The
                                                0
    operations for each of terms is as follows:

    如果奇数，则可以使用奇偶校验测试来测试对术语的依赖性

    比特数为真，则需要对该项进行求值。对于

    例如，任何奇怪的ROP都必须对a项进行评估。
    						0
    每个术语的操作如下：


       5) a           ~
           0

          a           ^ DST
           d

          a           ^ SRC
           s

          a           ^ PAT
           p

          a           ^ (DST & SRC)
           ds

          a           ^ (DST & PAT)
           dp

          a           ^ (SRC & PAT)
           sp

          a           ^ (DST & SRC & PAT)
           dsp


    Take for example the ROP 87 (01010111) the expression for it would be:

    以ROP 87（01010111）为例，其表达式为：


        ~0 ^ (DST & SRC) ^ (DST & PAT) ^ (DST & SRC & PAT)



    Some other common ROP codes:

    其他一些常见的ROP代码：

    ROP       RPN     Compiled

     00       0       0
     0F       Pn     ~0 ^ PAT
     11       DSon   ~0 ^ DST ^ SRC ^ (DST & SRC)
     33       Sn     ~0 ^ SRC
     44       SDna    0 ^ SRC ^ (DST & SRC)
     66       DSx     0 ^ SRC ^ DST
     88       DSa     0 ^ (SRC & DST)
     AA       D       0 ^ DST
     BB       DSno   ~0 ^ SRC ^ (DST & SRC)
     C0       PSa     0 ^ (SRC & PAT)
     CC       S       0 ^ SRC
     EE       DSo     0 ^ SRC ^ DST ^ (DST & SRC)
     F0       P       0 ^ PAT
     FB       DPSnoo ~0 ^ SRC ^ (DST & SRC) ^ (SRC & PAT) ^ (DST & SRC & PAT)
     FF       1      ~0

    Some simple constant folding can be done to eliminate the 0 from most of
    these expressions, since 0 ^ N always gives N.

    可以进行一些简单的常量折叠，以从大多数
    这些表达式，因为0^N总是给出N。
